/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csse3004.GD.PC;

import csse3004.GD.DA.PollCreatorDA;
import javax.servlet.ServletException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;
import org.springframework.web.servlet.view.RedirectView;

/**
 *
 * @author Lewis Kelly 42007689
 */
public class addSpecMCQController extends SimpleFormController {

    protected final Log logger = LogFactory.getLog(getClass());
    private PollCreatorService pollCreatorService = new PollCreatorDA();
    ModelAndView mnv = new ModelAndView("success");

    public ModelAndView onSubmit(Object command) throws ServletException {
        String success = "Your question has been successfully submitted!!";
        String failure = "Your question was not successfully submitted, please try again";
        
        addSpecMCQ co = (addSpecMCQ) command;
        String qrank;
        String qdemo;
        String qcomp;
        String qtext = co.getQuestionText();
        String qtemplate = "No";
        String qtype = co.getStyle();
        int id = co.getPollID();
        int type = co.getqStyle();
        if (type == 1) {
            qrank = "No";
            qdemo = "Yes";
            qcomp = "No";
            pollCreatorService.addMCQuestion(qtext, qtype, qtemplate, qrank, qdemo, qcomp, id);
            logger.info("Demographic"+type);
            mnv.addObject("succ", success);
            return mnv;
        } else if (type == 2) {
            qrank = "No";
            qdemo = "No";
            qcomp = "Yes";
            logger.info("Comparative"+type);
            pollCreatorService.addMCQuestion(qtext, qtype, qtemplate, qrank, qdemo, qcomp, id);
            mnv.addObject("succ", success);
            return mnv;
        } else if (type == 3) {
            qrank = "Yes";
            qdemo = "No";
            qcomp = "No";
            logger.info("Ranking"+type);
            pollCreatorService.addMCQuestion(qtext, qtype, qtemplate, qrank, qdemo, qcomp, id);
            mnv.addObject("succ", success);
            return mnv;
        } else {
            mnv.addObject("fail", failure);
            return mnv;
        }
    }
}
